<?php

class Application_Model_Apptag extends Zend_Db_Table_Abstract
{

    protected $_name = "kp_app_tag"; //Ten bang
    //protected $_primary = "tag_id"; //Khoa chinh
    protected $db;
    //Cac truong du lieu
    var $tag_id;
    var $app_id;
    
    //Ham khoi tao
    public function __construct(){
        $this->db = Zend_Registry::get('db');
    }
    
    //Get all user
    public function getAll($status=-1){
        $query = $this->db->select();
        $query->from($this->_name);
        if($status!=-1)$query->where('tag_view = ?',$status);
        $query->order(array('tag_name'));
        return $this->db->fetchAll($query);
    }
    
    //Them mới user
    public function insertNew(){
        $data = array(
                'tag_id' => $this->tag_id,
                'app_id' => $this->app_id,
        );
        //var_dump($data); die;
        return $this->db->insert($this->_name,$data);
    }
    
    public function getExist(){
        $query = $this->db->select();
        $query->from($this->_name);
        $query->where('tag_id = ?',$this->tag_id);
        $query->where('app_id = ?',$this->app_id);
        return $this->db->fetchRow($query);
    }
}

